/*
 * @描述:
 * @作者: 约訂
 * @Date: 2024-10-30 14:54:31
 * @LastEditTime: 2024-11-15 13:22:54
 * @修改人员: 约訂
 */
// import { ref, reactive, getCurrentInstance } from "vue";
// const { proxy } = getCurrentInstance() as any;
/**点击群组后获取的群成员更新 */
const correspondingUser = async (
  oldList: any[],
  newList: any[],
  oldId: any,
  newId: any
) => {
  let list: any[] = oldList;
  newList.forEach((item: any) => {
    item.open = false;
    item.list = [];
    if (oldId == newId) {
      list = list.filter(async function (el: any, idx) {
        if (el.QuestionUserId == item.QuestionUserId) {
          // console.log(el);
          item.open = el.open;
          item.list = el.list;
        }
        return el.QuestionUserId === item.QuestionUserId;
      });
    }
  });
  // console.log(newList);
  return newList;
};
/**检测在线客服 */
const examineList = async (list: any[], row: any[]) => {
  // console.log();

  row.forEach((item: any, index: any) => {
    item.online = false;
    for (let index = list.length - 1; index >= 0; index--) {
      if (item.UserId == list[index]) {
        item.online = false;
        list.splice(index, 1);
      }
    }
  });
  return row;
};
let debounceTimer: any = null;
const debounce = (callback: any, itemUser: any, duration: any = 500) => {
  // console.log(callback);
  return function (...args: any) {
    // console.log(args);
    if (debounceTimer) clearTimeout(debounceTimer);
    debounceTimer = setTimeout(() => {
      console.log("定时器函数执行了");
      // console.log(callback);
      callback(itemUser);
    }, duration);
  };
};
/**修改某一个记录的状态 */
const reviseState = async (localStorageData: any, data: any) => {
  localStorageData.list.some((item: any) => {
    if (item.Id == data.QuestionId && item.Record == 1) {
      item.IsAnswer = 1;
      console.log("修改的对象", item);

      return true;
    }
  });
  return localStorageData;
};
/**修改某一个记录的状态 */
const saveChatMessage = () => {};
/** */
const getChatHistory = async () => {};
// /** */
const createNewObjectStore = async () => {};
export { correspondingUser, debounce, reviseState, examineList };
